<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文本编辑器</title>
    <script type="text/javascript">
        function setColor(obj) {
            document.execCommand('ForeColor',false,obj.value);
        }
        function setFontSize(obj) {
            document.execCommand('FontSize',false,obj.value);
        }
    </script>
</head>
<body>
    <div>
        <form>
            颜色：<input type="color" oninput="setColor(this)"/>&nbsp;&nbsp;
            字号：
            <select onchange="setFontSize(this)">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
            </select>
            &nbsp;&nbsp;
            样式：
            <select onchange="document.execCommand(value)">
                <option value="bold">Bold</option>
                <option value="italic">Italic</option>
                <option value="underline">Underline</option>
            </select>
            &nbsp;&nbsp;
            字体：
            <select onchange="document.execCommand('FontName',false,value)">
                <option value="serif">Serif</option>
                <option value="sans-serif">Sans-serif</option>
                <option value="monospace">Monospace</option>
                <option value="comic sans ms">Comic Sans</option>
            </select>
            <input type="button" value="Cut" onclick="document.execCommand('Cut')">
            <input type="button" value="Paste" onclick="div1.focus();document.execCommand('Paste')">
        </form>
    </div>
    <br/>
    <div name="div1" contenteditable="true" style="width: 100%;height: 300px;border: 2px dashed #ccc">
        HTML CSS JS<br>
        document.execCommand<br>
        http://www.w3cshool.cn <br>
        IE:document.execCommand('paste') <br>
        Chrome:color
    </div>
</body>
</html>